import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:todo_app/components/TextExt.dart';
import 'package:todo_app/constants/DColor.dart';
import 'package:todo_app/constants/ImageAssets.dart';
import 'package:todo_app/hooks/PackageInfo.dart';
import 'package:todo_app/layout/CustomCard.dart';
import 'package:todo_app/layout/Gaps.dart';
import 'package:todo_app/layout/Header.dart';
import 'package:todo_app/layout/ListItem.dart';
import 'package:todo_app/utils/PgyerUpgradeHelper.dart';
import 'package:url_launcher/url_launcher_string.dart';

class AboutUsPage extends HookWidget {
  const AboutUsPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    var packageInfo = usePackageInfo();
    var upgrade = useCallback(() {
      PgyerUpgradeHelper.checkUpgrade(showLoading: true, showToast: true).then((res) async {
        if(res != null) {
          var upgrade = await PgyerUpgradeHelper.showUpgradeConfirmDialog(res);
          if(upgrade && res.downloadURL != null) {
            launchUrlString(res.downloadURL!, mode: LaunchMode.externalNonBrowserApplication);
          }
        }
      });
    }, []);
    return Scaffold(
      backgroundColor: DColor.bgColor,
      appBar: const Header(title: "关于我们"),
      body: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            CustomCard(
              bgColor: Colors.white,
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Container(
                    alignment: Alignment.center,
                    margin: EdgeInsets.only(
                      top: 180.dp,
                      bottom: 12.dp
                    ),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(15.dp),
                      child: Image.asset(ImageAssets.commonLogoPng, width: 100.dp, height: 100.dp,)
                    ),
                  ),
                  Center(
                    child: TextExt.desc("待办事项 ${packageInfo?.version}-${packageInfo?.buildNumber}", textAlign: TextAlign.center),
                  ),
                  SizedBox(height: 100.dp)
                ],
              )
            ),
            CustomCard(
              margin: EdgeInsets.only(
                top: 15.dp
              ),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  ListItem(
                    height: 44.dp,
                    title: TextExt.title("版本更新", lineHeight: 1), 
                    nextIcon: true, 
                    onTap: upgrade,
                  )
                ]
              )
            ),
          ],
        )
      ),
    );
  }
}